package com.zf.zffencheng.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zf.zffencheng.dao.AccountDao;
import com.zf.zffencheng.model.pojo.TAccount;
import com.zf.zffencheng.model.vo.AccountVo;
import com.zf.zffencheng.model.vo.AdminLoginInfoVo;
import com.zf.zffencheng.model.vo.HomePageVo;
import com.zf.zffencheng.service.AccountService;
import com.zf.zffencheng.service.AdminService;
import com.zf.zffencheng.service.CapitalOrderProfitService;
import com.zf.zffencheng.util.BeanUtils;
import com.zf.zffencheng.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;

/**
 * ClassName: AccountServiceImpl <br/>
 * Description:  <br/>
 * date: 2021/5/11 17:30<br/>
 *
 * @author william <br/>
 */
@Service
public class AccountServiceImpl  extends ServiceImpl<AccountDao, TAccount> implements AccountService {
    @Autowired
    private AdminService adminService;
    @Autowired
    private CapitalOrderProfitService capitalOrderProfitService;

    /**
     * 获取账户
     *
     * @param currentAdminInfo
     * @return
     */
    @Override
    public AccountVo getAccount(AdminLoginInfoVo currentAdminInfo) {
        Integer adminType = currentAdminInfo.getAdminType();
        //Integer accountId = currentAdminInfo.getAccountId();
        Integer accountId = currentAdminInfo.getAdminId();
        return pojoToVo(byAccountIdAndType(accountId, adminType));
    }

    @Override
    public HomePageVo getHomePageVo(Integer adminId, Integer accountId, Integer adminType) {
        return capitalOrderProfitService.getHomePageVo(adminId,accountId,adminType);
    }


    /**
     * 查询账户id与账户类型
     * @param accountId
     * @param type
     * @return
     */
    public TAccount byAccountIdAndType(Integer accountId, Integer type){

        QueryWrapper<TAccount> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("accountId", accountId);
        queryWrapper.eq("type", type);
        return getOne(queryWrapper, false);
    }

    /**
     * pojo
     * @param tAccount
     * @return
     */
    public AccountVo pojoToVo(TAccount tAccount){
        return BeanUtils.copyAs(tAccount, AccountVo.class);
    }
}
